package com.second.app.thread.join.exception;

/**
 * @author gyz
 * @date 2021/1/28 13:44
 */
public class ThreadA extends Thread {
    @Override
    public void run() {
        //模拟耗时操作
        for (int i = 0; i < Integer.MAX_VALUE; i++) {
            String newString = new String();
            Math.random();
        }
    }
}

class ThreadB extends Thread {
    @Override
    public void run() {
        try {
            ThreadA threadA = new ThreadA();
            threadA.start();
            threadA.join();//加入到当前线程
            System.out.println("线程B正常结束");
        } catch (InterruptedException e) {
            throw new RuntimeException("线程B异常结束");
        }
    }
}

class ThreadC extends Thread {
    private ThreadB threadB;

    public ThreadC(ThreadB threadB) {
        this.threadB = threadB;
    }

    @Override
    public void run() {
        threadB.interrupt();
    }
}
